package com.caesar.exer2;

/**
 * @author caesar
 * @date 2025/7/21
 * @Description:
 * @apiNote
 */
public class TestRacer {
    public static void main(String[] args) {
        Racer.setDistance(30);
        Racer rabbit = new Racer("兔子", 100, 10000);
        Racer tortoise = new Racer("乌龟", 1000, 1000);

        rabbit.start();
        tortoise.start();

        while(true){
            if (!rabbit.isAlive() || !tortoise.isAlive()){
                if(!Racer.isRunFlag()){
                    System.out.println("比赛结束");
                    rabbit.interrupt();
                    tortoise.interrupt();
                    if (rabbit.isFinished() && tortoise.isFinished()){
                        if (rabbit.getTime() < tortoise.getTime()){
                            System.out.println("兔子赢");
                        } else if (rabbit.getTime() > tortoise.getTime()){
                            System.out.println("乌龟赢");
                        } else {
                            System.out.println("平局");
                        }
                    } else if (rabbit.isFinished() ){
                        System.out.println("兔子赢");
                    } else if(tortoise.isFinished()){
                        System.out.println("乌龟赢");
                    }
                }else{
                    System.out.println("乌龟和兔子都没有到达终点比赛取消");
                }
                break;
            }
        }
    }
}